{extend name="common/base_page" /}

{block name="title"}药品/材料{/block}

{block name="jscssfile"}
<link href="__STATIC__/easy_search/searchPlug.css?v={$site.version}" type='text/css'/>
{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
.layui-fluid {
    padding:10px 15px;
}
.layui-tab {
    margin: 0 0;
}
.layui-tab-content{  
  padding-top:0px;
}
.layui-tab-content .layui-tab-item{
  height:100vh;
}
.layui-tab-card>.layui-tab-title .layui-this {
    background-color: #fff;
    color: #1e9fff;
    font-weight: bold;
}
#bar_box_one{
  padding:10px 20px 5px 20px;
  margin-bottom:0px;
}
.layui-table, .layui-table-view { margin:0; }
.drugs_guige .layui-inline{margin-right: 0;}
</style>
{/block}

{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12" style="height:100vh;padding:0;">

            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    <li data-type="xy" class="layui-this">西药/中成药</li>
                    <li data-type="zy">中药</li>
                    <li data-type="cl">材料</li>
                </ul>
                <div class="layui-form-item" id="bar_box_one">
                    <a class="layui-btn layui-btn-normal" onclick="_addAction();">添加</a>
                    <div class="layui-input-block" style="float: right;">
                      <form class="layui-form" action="">
                          <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                              <select id="status" name="status">
                                  <option value="ALL">所有</option>
                                  <option value="0">已停用</option>
                                  <option value="1">已启用</option>
                              </select>
                            </div>
                          </div>
                          <div class="layui-inline">
                            <div class="layui-input-inline">
                              <input type="text" name="keyword" id="keyword" maxlength="10" placeholder="请输入键词" autocomplete="off" class="layui-input">
                            </div>
                          </div>
                          <div class="layui-inline">
                                <a class="layui-btn layui-btn-normal" onclick="_p = 1;_loadList();">搜索</a>
                          </div>
                        </form>
                    </div>
                </div>
                <div class="layui-tab-content">
                      <div class="layui-tab-item layui-show">
                          <table id="LAY-app-content-comm" lay-filter="LAY-app-content-comm"></table>
                      </div>
                </div>
            </div>

        </div>
    </div>
</div>
{/block}

{block name="script"}
<script type="text/html" id="statusTpl">
  {{#  if(d.status){ }}
    <button class="layui-btn layui-btn-xs">已启用</button>
  {{#  } else { }}
    <button class="layui-btn layui-btn-primary layui-btn-xs">已停用</button>
  {{#  } }}
</script>
<script type="text/html" id="table-content-com">
  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script type="text/javascript">
var _p = 1, _isFirst = true, _dictText = '', _dictType = 'xy', _findSysUrl = "{:url('index/dictionary.drugs/find_sysdrug')}";
$(function(){
  $('.layui-tab-title li').click(function(e){
      var _tmpType = $(this).data('type');
      if(_tmpType != _dictType || _isFirst)
      {
          $(this).addClass('layui-this');
          $(this).siblings().removeClass('layui-this');
          if(_isFirst) _isFirst = false;
          _dictText = $(this).text();
          _dictType = _tmpType;
          _p = 1;
          _loadList();
      }
  });
  setTimeout(function(){
      $('.layui-tab-title li:first').trigger('click');
  },50);
});
</script>

{include file="js_template/tpl_yaopin_cl" /}
<script src="__STATIC__/easy_search/searchPlug.js?v={$site.version}"></script>
<script src="__INDEX__/js/common/hz2pinyin.js"></script>
<script src="__INDEX__/js/common/hz2wubi.js"></script>
<script src="__INDEX__/js/common/commonUtils.js?v={$site.version}"></script>
<script src="__INDEX__/js/zidian/drugs.js?v={$site.version}"></script>

<script type="text/javascript">
//加载数据
function _loadList()
{
      __showLoadingBox('请稍候...');
      laytable.render({
          elem: '#LAY-app-content-comm'//指定表格元素
          ,url:"{:url('index/dictionary.drugs/index')}"
          ,method:'post'  //提交方式
          ,where:{keyword:$.trim($('#keyword').val()),status:$.trim($('#status').val()),page:_p,dicttype:_dictType} //post json数据
          ,page: {layout: ['count', 'prev', 'page', 'next', 'skip'],first: true,last: true}
          ,skin: 'line '  //表格风格 line （行边框风格）row （列边框风格）nob （无边框风格）
        　,even: true    //隔行换色
          ,limit: 20     //每页默认显示的数量
          ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
          ,height: 'full-100' //表格高度，layui 2.2.1 新增 , full-100 为适应最大高度或其它数值500
          ,cols: getTableConfigField()
          ,done:function(datalist,curr,page){
              __hideLoadingBox();
          }
      });

      laytable.on('tool(LAY-app-content-comm)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var _data = obj.data; //获得当前行数据
          var _event = obj.event; //获得 lay-event 对应的值
          if(_event === 'edit'){ //编辑
              _addAction(_data);
          }
          if(_event === 'del'){ //删除
            layer.confirm('您确定要删除本条数据吗？', {
                title:'删除',shade:[0.4,'#000000'],btn: ['确定','取消'] //按钮
            }, function(){
                layer.closeAll();
                _Index.ajax("{:url('index/dictionary.drugs/del')}",{id:_data.id,dicttype:_dictType},function(d){
                    if(d.err == 0)
                    {
                      obj.del();
                      layer.msg(d.msg, {time: 1000},function(){
                          laytable.reload('LAY-app-content-comm');
                      });
                    }else{
                      layer.msg(d.msg, {time: 2000,anim: 4});
                    }
                },'请稍候...');
            });
          }
      });
}
</script>
{/block}